<?php
namespace App\Http\Controllers\WebApi\CenterCompany;

use App\Repositories\OrdersRepository;
use Illuminate\Http\Request;

class OrderController extends BaseController
{
    /**
     * 公司信息
     */

    protected $order;

    public function __construct()
    {
        parent::__construct();
        $this->order = new OrdersRepository();
    }

    /**
     * 原料面料获取
     */
    public function getFabric(Request $request)
    {
        //用户登陆判断
        $token = $request->post('token','');
        $uid = $this->getUidByToken($token);
        if (!$uid) {
            return $this->toJson(-9);
        }
        $orderId = $request->post('orderId',0);
        $fabrics = $this->order->getFabric($orderId);
        if (!$fabrics) {
            return $this->toJson(-3);
        }
        $dataArr = $fabrics;
        return $this->toJson(0,$dataArr);
    }

    /**
     * 原料面料设置
     */
    public function setFabric(Request $request)
    {
        //用户登陆判断
        $token = $request->post('token','');
        $uid = $this->getUidByToken($token);
        if (!$uid) {
            return $this->toJson(-9);
        }
        //获取参数
        $orderId = $request->post('orderId',0);
        $fabrics = $request->post('fabrics','');
        if (!$fabrics) {
            return $this->toJson(-2);
        }
        $orderOne = $this->order->getFabric($orderId);
        if (!$orderOne) {
            return $this->toJson(-3);
        }
        $resOrder = $this->order->setFabric($orderId,$fabrics);
        if (!$resOrder) {
            return $this->toJson(-10);
        }
        return $this->toJson(0);
    }

    /**
     * 订单合同获取
     */
    public function getContract(Request $request)
    {
        //用户登陆判断
        $token = $request->post('token','');
        $uid = $this->getUidByToken($token);
        if (!$uid) {
            return $this->toJson(-9);
        }
        //获取参数
        $baleId = $request->post('baleId',0);
        if (!$baleId) {
            return $this->toJson(-2);
        }
        $resOrder = $this->order->getContract($baleId);
        if (!$resOrder) {
            return $this->toJson(-10);
        }
        $dataArr = $resOrder;
        return $this->toJson(0,$dataArr);
    }

    /**
     * 订单合同设置
     */
    public function setContract(Request $request)
    {
        //用户登陆判断
        $token = $request->post('token','');
        $uid = $this->getUidByToken($token);
        if (!$uid) {
            return $this->toJson(-9);
        }
        //获取参数
        $baleId = $request->post('baleId',0);
        $cid = $request->post('cid',0);
        $fid = $request->post('fid',0);
        $file = $request->post('file','');
        if (!$baleId || !$file) {
            return $this->toJson(-2);
        }
        $contracts = [
            'cid' => $cid,
            'fid' => $fid,
            'file' => $file,
        ];
        $resOrder = $this->order->setContract($baleId,$contracts);
        if (!$resOrder) {
            return $this->toJson(-10);
        }
        return $this->toJson(0);
    }

    /**
     * 订单草稿保存
     */
    public function setDraft(Request $request){}

    /**
     * 订单发布
     */
    public function setPublish(Request $request){}

    /**
     * 订单保证金
     */
    public function setBail(Request $request){}

    /**
     * 抢单动作
     */
    public function setApply(Request $request){}

    /**
     * 抢单列表
     */
    public function setApplyList(Request $request){}

    /**
     * 订单交流
     */
    public function getTalk(Request $request){}

    /**
     * 订单合作确认
     */
    public function setCooperate(Request $request){}

    /**
     * 订单预付款
     */
    public function setCharge(Request $request){}

    /**
     * 订单原料发送
     */
    public function setFabricSendRequest $request){}

    /**
     * 订单原料签收
     */
    public function setFabricAccept(Request $request){}

    /**
     * 订单生产
     */
    public function setProduce(Request $request){}

    /**
     * 订单跟单
     */
    public function setQc(Request $request){}

    /**
     * 订单跟单确认
     */
    public function setQcSure(Request $request){}

    /**
     * 订单生产完成
     */
    public function setMakeOk(Request $request){}

    /**
     * 订单打包发货
     */
    public function setDelivery(Request $request){}

    /**
     * 订单签收
     */
    public function setSign(Request $request){}

    /**
     * 订单评价
     */
    public function setComment(Request $request){}
}